package com.hdaccp.foodsales.controller;


import com.hdaccp.foodsales.entity.Danwei;
import com.hdaccp.foodsales.entity.Shangpin;
import com.hdaccp.foodsales.entity.Xiaoclass;
import com.hdaccp.foodsales.service.ShangpinService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/shangPin")
@Scope("prototype")
public class ShangpinController1 {
    @Autowired
    private ShangpinService1 shangpinService;
    @RequestMapping("/queryPage")
    @ResponseBody
    public Map<String,Object> queryPage(String sname,int offset,int limit){
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows",shangpinService.queryPage(sname,offset,limit));
        map.put("total",shangpinService.countA(sname));
        return map;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public int delete(int sid){
        return shangpinService.deleteA(sid);
    }


    /**
     * 商品增加
     * @param shangpin
     * @return
     */
    @RequestMapping("/add")
    @ResponseBody
    public int add(Shangpin shangpin){
        return shangpinService.addA(shangpin);
    }

    /**
     * 商品更改
     * @param shangpin
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public int update(Shangpin shangpin){
        return shangpinService.updateA(shangpin);
    }

    /**
     * 获取商品编号
     * @param sid
     * @return
     */
    @RequestMapping("/getsid2")
    @ResponseBody
    public Shangpin getsid2(int sid){
        return shangpinService.getsid1(sid);
    }


    /**
     * 查询类别
     * @return
     */
    @RequestMapping("/select")
    @ResponseBody
    public List<Xiaoclass> select(){
        return shangpinService.select1();
    }

    /**
     * 查询单位
     * @return
     */
    @RequestMapping("/selectdw")
    @ResponseBody
    public List<Danwei> selectdw(){
        return shangpinService.selectdw();
    }


    }
